<?php
/**
 * Interface to delete a center
 * 
 * @author Xavier 
 * 
 */

use Fox\Generator;
$xview = Xview::instance();
$id = $xview->val('mcid');
/* @var $objectToDelete Nawa\MedicalCenter */
$objectToDelete = $xview->component('medicalcenters','object',array('mcid' => $id));
$label = $objectToDelete->label();

if($xview->val("confirmation"))
{
	try {
		$objectToDelete->delete();
		Fox\Message::Information(Msg(Fox::MSGCL,Fox\Msg::MSG_DELETE,$label));
		exit;
	}
	catch (Fox\Object\Exception\Save $e)
	{
		Fox\Message::Error($e->getMessage());
	}
}

$reloadGen = Generator::redirect(Generator::url('medicalcenters','search'));
$yesAction = Generator::ajax(Generator::url('update.php','delete',null,array('mcid' => $id)),
							'&confirmation=true',
							$reloadGen,'hdeleteForm','RF',2
);
$popup = new Fox\Popup\ToConfirm("deleteForm",Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_DELETE_HDR), Msg(Nawa\Messages::BUNDLE,Nawa\Messages::MC_DELETE_CONFIRMATION,$label),$yesAction,null,400);
echo $popup->Display();